www.gusucode.com > VC++ 通达信系统设置V3.0-源码程序 > VC++ 通达信系统设置V3.0-源码程序/code/CfgPage.cpp
// CfgPage.cpp : implementation file // Download by http://www.NewXing.com #include "stdafx.h" #include "tdxwcfg.h" #include "CfgPage.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CCfgPage property page IMPLEMENT_DYNCREATE(CCfgPage, CPropertyPage) CCfgPage::CCfgPage() : CPropertyPage(CCfgPage::IDD) { //{{AFX_DATA_INIT(CCfgPage) m_strAdvert = _T(""); m_time = 0; m_Content = _T(""); m_strSource = _T(""); //}}AFX_DATA_INIT } CCfgPage::~CCfgPage() { } void CCfgPage::DoDataExchange(CDataExchange* pDX) { CPropertyPage::DoDataExchange(pDX); //{{AFX_DATA_MAP(CCfgPage) DDX_Control(pDX, IDC_CONTENT_EDIT, m_Content_Edit); DDX_Text(pDX, IDC_ADVERT_EDIT, m_strAdvert); DDV_MaxChars(pDX, m_strAdvert, 90); DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER, m_time); DDX_Text(pDX, IDC_CONTENT_EDIT, m_Content); DDV_MaxChars(pDX, m_Content, 2048); DDX_Text(pDX, IDC_URGENTSOURCE_EDIT, m_strSource); DDV_MaxChars(pDX, m_strSource, 30); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CCfgPage, CPropertyPage) //{{AFX_MSG_MAP(CCfgPage) ON_BN_CLICKED(IDC_LOADURGENT, OnLoadurgent) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CCfgPage message handlers CTime LongToTime(long ltmp) { CTime NowDate = CTime::GetCurrentTime(); if(ltmp <= 0) return NowDate; int year,month,day; year = ltmp / 10000; if(year <= 1900) return NowDate; month = (ltmp % 10000) / 100; if(month <= 0 && month > 12) return NowDate; day = (ltmp % 10000) % 100; if(day <= 0 && day > 31) return NowDate; return(CTime(year,month,day,0,0,0)); } long TimeToLong(CTime time) { long ltmp; ltmp = (time.GetDay()+time.GetMonth()*100)+time.GetYear()*10000; return ltmp; } BOOL CCfgPage::OnInitDialog() { CPropertyPage::OnInitDialog(); CFile CfgFile; m_time = CTime::GetCurrentTime(); CTimeSpan tempSpan(1,0,0,0); //下一天 m_time += tempSpan; if(CfgFile.Open(g_Yxhj+"urgent.dat",CFile::modeRead|CFile::shareDenyNone)) { if(sizeof(struct Cfg_Struct) == CfgFile.Read(&CfgStruct,sizeof(struct Cfg_Struct))) { m_strAdvert = CfgStruct.Advert; m_strSource = CfgStruct.UrgentSource; m_time = LongToTime(CfgStruct.EndTime); m_Content = CfgStruct.UrgentContent; } CfgFile.Close(); } UpdateData(FALSE); return TRUE; } void CCfgPage::OnOK() { UpdateData(TRUE); CFile CfgFile; if(CfgFile.Open(g_Yxhj+"urgent.dat",CFile::modeCreate|CFile::modeWrite)) { strcpy(CfgStruct.Advert,m_strAdvert); strcpy(CfgStruct.UrgentContent,m_Content); strcpy(CfgStruct.UrgentSource,m_strSource); CfgStruct.EndTime = TimeToLong(m_time); CfgFile.Write(&CfgStruct,sizeof(struct Cfg_Struct)); CfgFile.Close(); } CPropertyPage::OnOK(); } void CCfgPage::OnLoadurgent() { CString m_strFilePath; CFileDialog FileDialog(TRUE,NULL,NULL, OFN_NOCHANGEDIR, "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*||"); if (FileDialog.DoModal() == IDOK) { m_strFilePath = FileDialog.GetPathName(); CFile theFile; if(theFile.Open(m_strFilePath,CFile::modeRead)) { DWORD tmpLen = theFile.GetLength(); short readlen = min(tmpLen,2047); char *buf = (char *)malloc(readlen+1); theFile.Read(buf,readlen); buf[readlen] = 0; m_Content_Edit.SetWindowText(buf); free(buf); theFile.Close(); } } }